/**
 * 系统管理 地址配置管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>地址配置管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--列表-->
    <el-table
      size="small"
      :data="configData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%; margin-top: 2%"
    >
      <el-table-column
        align="center"
        sortable
        prop="value"
        label="店铺地址"
        width="600"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="sortOrder"
        label="排序"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="isShow"
        label="是否显示"
        width="100"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="updateTime"
        label="修改配置最终时间"
        width="200"
      >
      </el-table-column>
      <el-table-column label="操作" min-width="100" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
            type="primary"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 编辑界面 -->
    <el-dialog
      :title="title"
      :visible.sync="editFormVisible"
      width="60%"
      @click="closeDialog"
    >
      <el-form label-width="90px" :model="editForm" ref="editForm">
        <el-form-item label="店铺地址">
          <el-input
            size="small"
            v-model="editForm.value"
            auto-complete="off"
            placeholder="请输入店铺地址"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序">
          <el-input
            size="small"
            v-model="editForm.sortOrder"
            auto-complete="off"
            placeholder="请输入地址排序，默认50"
          ></el-input>
        </el-form-item>
        <el-form-item label="是否显示">
          <el-switch
            v-model="editForm.isShow == 1 ? nshow : fshow"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="editType"
          >
          </el-switch>
          <!-- <el-input size="small" v-model="editForm.isShow" auto-complete="off" placeholder="电话号码是否显示"></el-input> -->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button
          size="small"
          type="primary"
          :loading="loading"
          class="title"
          @click="submitForm(editForm)"
          >保存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入请求方法
import Pagination from "../../components/Pagination";
import { configList, updateConfig } from "../../api/systemMg";
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      title: "查看地址库",
      editFormVisible: false, //控制编辑页面显示与隐藏
      dataAccessshow: false, //控制数据权限显示与隐藏
      unitAccessshow: false, //控制所属单位隐藏与显示
      // 编辑与添加
      editForm: {
        id: 0,
        value: "",
        sortOrder: 50,
        isShow: 0,
      },
      // 请求数据参数
      formInline: {
        size: 1,
        current: 10,
      },
      //电话数据
      configData: [],
      pageparm: {
        current: 1,
        size: 10,
        total: 10,
      },
    };
  },
  // 注册组件
  components: {
    Pagination,
  },

  /**
   * 数据发生改变
   */
  watch: {},

  /**
   * 创建完毕
   */
  created() {
    this.formInline.current = 1;
    this.formInline.size = 10;
    let data = {
      pageVo: this.formInline,
      keys: ["ADDRESS"],
    };
    this.getdata(data);
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取数据方法
    async getdata(parameter) {
      this.loading = true;
      var that = this;
      // 获取用户列表
      await configList(parameter).then((res) => {
        if (res.code == "200") {
          that.loading = false;
          that.configData = res.data.records;
          that.pageparm.current = res.data.current;
          that.pageparm.size = res.data.size;
          that.pageparm.total = res.data.total;
        } else {
          // that.loading = true
          that.configData = [];
        }
      });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage;
      this.formInline.limit = parm.pageSize;
      let data = {
        pageVo: this.formInline,
        keys: ["ADDRESS"],
      };
      this.getdata(this.formInline);
    },

    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      this.editForm = {
        id: row.id,
        value: row.value,
        sortOrder: row.sortOrder,
        isShow: row.isShow,
      };
    },
    // 是否显示按钮处理
    // 修改type
    editType: function () {
      this.editForm.isShow == 1
        ? (this.editForm.isShow = 0)
        : (this.editForm.isShow = 1);
    },

    // 修改配置处理
    async submitForm(data) {
      let that = this;
      // 获取用户列表
      await updateConfig(data).then((res) => {
        if (res.code == "200") {
          that.closeDialog();
          this.$message({
            type: "success",
            message: "电话配置修改成功！",
          });
          let data = {
            pageVo: that.formInline,
            keys: ["ADDRESS"],
          };
          this.getdata(data);
        } else {
          // that.loading = true
          that.configData = [];
        }
      });
    },

    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 